﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class DangKyKhamBenhDAO
    {
        public static DataTable LayDanhSachDangKyKhamBenh()
        {
            string sql;
            sql = "SELECT * FROM DangKyKhamBenh";
            return DataAccess.ExecQuery(sql);
        }

        public static void ThemDangKyKhamBenh(DangKyKhamBenhDTO obj)
        {
            string sql;
            sql = string.Format(@"INSERT INTO DangKyKhamBenh(NgayDangKy, NgayKham, HoTen, NgaySinh, GioiTinh, DiaChi, YeuCauKham) VALUES(N'{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}')",
                                obj.NgayDangKy, obj.NgayKham, obj.HoTen, obj.NgaySinh, obj.GioiTinh, obj.DiaChi, obj.YeuCauKham);
            DataAccess.ExecNonQuery(sql);
        }

        public static void SuaDangKyKhamBenh(DangKyKhamBenhDTO obj)
        {
            string sql;
            sql = string.Format(@"UPDATE DangKyKhamBenh SET NgayDangKy = N'{0}', NgayKham = N'{1}', HoTen = N'{2}', NgaySinh = N'{3}', GioiTinh = N'{4}', DiaChi = N'{5}',  YeuCauKham = N'{6}' 
                WHERE MaDKKB = '{9}'", obj.NgayDangKy, obj.NgayKham, obj.HoTen, obj.NgaySinh, obj.GioiTinh, obj.DiaChi, obj.YeuCauKham);
            DataAccess.ExecNonQuery(sql);
        }

        public static void XoaDangKyKhamBenh(int maDangKyKhamBenh)
        {
            string sql;
            sql = string.Format("DELETE DangKyKhamBenh WHERE MaDKKB = {0}", maDangKyKhamBenh);
            DataAccess.ExecNonQuery(sql);
        }

        public static DangKyKhamBenhDTO LayThongTinDangKyKhamBenhTheoMaDangKyKhamBenh(int maDangKyKhamBenh)
        {
            DangKyKhamBenhDTO kq = new DangKyKhamBenhDTO();
            string sql;
            sql = @"select * from DangKyKhamBenh where MaDKKB = " + maDangKyKhamBenh;
            DataTable dt = DataAccess.ExecQuery(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                kq.MaDKKB = Convert.ToInt32(dt.Rows[0]["MaDKKB"]);
                kq.NgayDangKy = Convert.ToDateTime(dt.Rows[0]["NgayDangKy"]);
                kq.NgayKham = Convert.ToDateTime(dt.Rows[0]["NgayKham"]);
                kq.HoTen = Convert.ToString(dt.Rows[0]["HoTen"]);
                kq.NgaySinh = Convert.ToDateTime(dt.Rows[0]["NgaySinh"]);
                kq.GioiTinh = Convert.ToString(dt.Rows[0]["GioiTinh"]);
                kq.DiaChi = Convert.ToString(dt.Rows[0]["DiaChi"]);
                kq.YeuCauKham = Convert.ToString(dt.Rows[0]["YeuCauKham"]);
            }
            return kq;
        }
    }
}
